<%--
  Created by IntelliJ IDEA.
  User: 轩
  Date: 2019/1/19
  Time: 10:01
  To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <title>财务管理-收入单</title>
    <link rel="stylesheet" href="/layuiadmin/layui/css/layui.css" media="all">
    <script type="text/javascript" src="../../../js/jquery-1.8.3.js"></script>
    <style>
        body{margin: 10px;}
        .demo-carousel{height: 200px; line-height: 200px; text-align: center;}
    </style>
</head>
<body>
<div>
    <form class="layui-form layui-from-item" action="">
        <div class="layui-inline">
            <div class="layui-input-inline">单据编号:&nbsp</div>
            <div class="layui-input-inline" style="width: 200px;">
                <input type="text" name="chcCustName" id="billNo" placeholder="单据编号" autocomplete="off" class="layui-input">
            </div>
            <div class="layui-input-inline">&nbsp创建时间：</div>
            <div class="layui-input-inline" style="width: 200px;">
                <input  type="text" id="billTimeBefore" name="d1" lay-verify="datetime"  placeholder="起始时间" class="layui-input">
            </div>
            <div class="layui-input-inline">-</div>
            <div class="layui-input-inline" style="width: 200px;">
                <input  type="text" id="billTimeBack" name="d2" lay-verify="datetime"  placeholder="截止时间" class="layui-input">
            </div>
        </div>
        <div class="layui-inline" style="">
            <button class="layui-btn" type="button" id="chaxun">查询</button>
            <button type="reset" class="layui-btn" id="chongzhi" style="margin-left: -3px">重置</button>
        </div>
    </form>
</div>

<table class="layui-hide" id="demo" lay-filter="test"></table>

<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">查看</a>
    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>

<script src="/layuiadmin/layui/layui.js" charset="utf-8"></script>
<script>
    layui.config({
        version: '1545041465443' //为了更新 js 缓存，可忽略
    });

    layui.use(['laydate', 'laypage', 'layer', 'table', 'carousel', 'upload', 'element', 'slider','form','jquery'], function(){
        var laydate = layui.laydate //日期
            ,laypage = layui.laypage //分页
            ,layer = layui.layer //弹层
            ,table = layui.table //表格
            ,carousel = layui.carousel //轮播
            ,upload = layui.upload //上传
            ,element = layui.element //元素操作
            ,slider = layui.slider //滑块
            ,form = layui.form //表单
            ,$ = layui.jquery;
        //向世界问个好
        // layer.msg('Hello World');




        //弹出日历框
        laydate.render({
            elem: '#billTimeBefore'
            ,type: 'datetime'
        });
        //弹出日历框
        laydate.render({
            elem: '#billTimeBack'
            ,type: 'datetime'
        });

        //监听Tab切换
        element.on('tab(demo)', function(data){
            layer.tips('切换了 '+ data.index +'：'+ this.innerHTML, this, {
                tips: 1
            });
        });

        //执行一个 table 实例
        table.render({
            elem: '#demo'
            ,method:"POST"
            ,url: '/income/selectAll' //数据接口
            ,id: 'idTest'
            ,where: {type: '付款'}
            ,title: '收支单数据'
            ,page: true //开启分页
            ,toolbar: 'default' //开启工具栏，此处显示默认图标，可以自定义模板，详见文档
            ,totalRow: false //开启合计行
            ,defaultToolbar: Array
            ,cols: [[ //表头
                {type: 'checkbox', fixed: 'left'}
                ,{field:'supplier', title:'往来单位', width:200, fixed: 'left', unresize: true, sort: true}
                ,{field:'billNo', title:'单据编号', width:220, edit: 'text'}
                ,{field:'pName', title:'经手人', width:150, edit: 'text'}
                ,{field:'billTime', title:'单据时间', width:200, edit: 'text', sort: true}
                ,{field:'accountId', title:'合计', width:120}
                ,{field:'remark', title:'备注'}
                ,{fixed: 'right', width: 165, align:'center', toolbar: '#barDemo'}
            ]]
        });

        //监听头工具栏事件
        table.on('toolbar(test)', function(obj){
            var checkStatus = table.checkStatus(obj.config.id)
                ,data = checkStatus.data; //获取选中的数据
            switch(obj.event){
                case 'add':
                    layer.open({
                        type: 2,
                        content: '/erp_market/add/paymentOrderadd', //这里content是一个URL，如果你不想让iframe出现滚动条，你还可以content: ['http://sentsin.com', 'no']
                        area: ['800px', '600px']
                    });
                    layer.msg('添加成功');
                    break;
                case 'update':
                    if(data.length === 0){
                        layer.msg('请选择一行');
                    } else if(data.length > 1){
                        layer.msg('只能同时编辑一个');
                    } else {
                        layer.alert('编辑 [id]：'+ checkStatus.data[0].id);
                    }
                    break;
                case 'delete':
                    if(data.length === 0){
                        layer.msg('请选择一行');
                    } else {
                        layer.msg('删除');
                        console.log(data);
                        var accountId="";
                        for(var i=0;i<data.length;i++){
                            accountId += data[i].accountId+",";
                        }
                        console.log(accountId);
                        $.ajax({
                            url: "/income/deleteAll/"+accountId,
                            type:"delete",
                            success: function () {
                                location.reload();
                                layer.msg("删除成功");
                            }
                        })
                    }
                    break;
            }
        });

        //监听行工具事件
        table.on('tool(test)', function(obj){ //注：tool 是工具条事件名，test 是 table 原始容器的属性 lay-filter="对应的值"
            var data = obj.data //获得当前行数据
                ,layEvent = obj.event; //获得 lay-event 对应的值
            if(layEvent === 'detail'){
                layer.msg('查看操作');
            } else if(layEvent === 'del'){
                layer.confirm('真的删除行么', function(index){
                    obj.del(); //删除对应行（tr）的DOM结构
                    layer.close(index);
                    //向服务端发送删除指令
                    console.log(data);
                    console.log(data.accountId);

                    $.ajax({
                        url: "/income/delete/"+data.accountId,
                        type:"delete",
                        success: function () {
                            location.reload();
                            layer.msg("删除成功");
                        }
                    })

                });
            } else if(layEvent === 'edit'){
                layer.msg('编辑操作');
            }
        });

        //执行一个轮播实例
        carousel.render({
            elem: '#test1'
            ,width: '100%' //设置容器宽度
            ,height: 200
            ,arrow: 'none' //不显示箭头
            ,anim: 'fade' //切换动画方式
        });

        //将日期直接嵌套在指定容器中
        var dateIns = laydate.render({
            elem: '#laydateDemo'
            ,position: 'static'
            ,calendar: true //是否开启公历重要节日
            ,mark: { //标记重要日子
                '0-10-14': '生日'
                ,'2018-08-28': '新版'
                ,'2018-10-08': '神秘'
            }
            ,done: function(value, date, endDate){
                if(date.year == 2017 && date.month == 11 && date.date == 30){
                    dateIns.hint('一不小心就月底了呢');
                }
            }
            ,change: function(value, date, endDate){
                layer.msg(value)
            }
        });

        //分页
        laypage.render({
            elem: 'pageDemo' //分页容器的id
            ,count: 100 //总页数
            ,skin: '#1e9fff' //自定义选中色值
            //,skip: true //开启跳页
            ,jump: function(obj, first){
                if(!first){
                    layer.msg('第'+ obj.curr +'页', {offset: 'b'});
                }
            }
        });

        //上传
        upload.render({
            elem: '#uploadDemo'
            ,url: '' //上传接口
            ,done: function(res){
                console.log(res)
            }
        });

        slider.render({
            elem: '#sliderDemo'
            ,input: true //输入框
        });



        /*模糊搜索*/
        $("#chaxun").on("click", function (){
            var billNos = $("#billNo").val();
            var billTimeBefores =$("#billTimeBefore").val();
            var billTimeBacks = $("#billTimeBack").val();

            //上述方法等价于
            table.reload('idTest', {
                where: { //设定异步数据接口的额外参数，任意设
                    billNo: 'billNos'
                    ,billTimeBefore: billTimeBefores
                    ,billTimeBack: billTimeBacks
                }
                ,page: {
                    curr: 1 //重新从第 1 页开始
                }
            });

        });

    });

</script>

</body>
</html>

